package com.mqz.zebraEcommerce.commodity.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.mqz.zebraEcommerce.commodity.entity.AttrAttrGroupRelationEntity;
import com.mqz.zebraEcommerce.commodity.service.AttrAttrGroupRelationService;
import com.mqz.zebraEcommerce.common.utils.PageUtils;
import com.mqz.zebraEcommerce.common.utils.R;

import javax.annotation.Resource;


/**
 * 商品属性和商品属性组的关联表
 *
 * @author mqz
 * @email 952905931@qq.com
 * @date 2025-03-04 15:01:21
 */
@RestController
@RequestMapping("commodity/attrAttrGroupRelation")
public class AttrAttrGroupRelationController {
    @Autowired
    private AttrAttrGroupRelationService attrAttrGroupRelationService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = attrAttrGroupRelationService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		AttrAttrGroupRelationEntity attrAttrgroupRelation = attrAttrGroupRelationService.getById(id);

        return R.ok().put("attrAttrgroupRelation", attrAttrgroupRelation);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody AttrAttrGroupRelationEntity attrAttrgroupRelation){
		attrAttrGroupRelationService.save(attrAttrgroupRelation);

        return R.ok();
    }

    /**
     * 保存关联
     */
    @RequestMapping("/saveBatch")
    public R saveBatch(@RequestBody List<AttrAttrGroupRelationEntity> relationEntities) {
        attrAttrGroupRelationService.saveBatch(relationEntities);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody AttrAttrGroupRelationEntity attrAttrgroupRelation){
		attrAttrGroupRelationService.updateById(attrAttrgroupRelation);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		attrAttrGroupRelationService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
